﻿<Window x:Class="SPConfigDBReaderApp.MainWindow"
		xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
		xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
		xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
		xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
		xmlns:local="clr-namespace:SPConfigDBReaderApp"
		xmlns:vm="clr-namespace:SPConfigDBReaderApp.ViewModels"
		xmlns:Extensions="clr-namespace:ITSparta.WPF.Extensions;assembly=ITSparta.WPF"
		mc:Ignorable="d"
		Extensions:WindowSettings.Save="True"
		Height="511" Width="1064"
		Title="{Binding Path=Name}">
	<Window.Resources>
		<Style TargetType="{x:Type TreeViewItem}" BasedOn="{StaticResource {x:Type TreeViewItem}}">
			<Setter Property="IsSelected" Value="{Binding Path=IsSelected, Mode=TwoWay}" />
			<Setter Property="IsExpanded" Value="{Binding Path=IsExpanded, Mode=TwoWay}" />
		</Style>

		<HierarchicalDataTemplate ItemsSource="{Binding Path=ChildClasses}" DataType="{x:Type vm:ClassViewModel}">
			<Grid VerticalAlignment="Top" HorizontalAlignment="Left" Height="16">
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition />
				</Grid.ColumnDefinitions>

				<TextBlock Text="{Binding Path=ClassName}" ToolTip="{Binding Path=ClassName}" />
				<TextBlock Grid.Column="1" Text="{Binding Path=Assembly}" ToolTip="{Binding Path=Assembly}" Margin="5,0,0,0" Foreground="{DynamicResource StrongBrush}" />

				<TextBlock Grid.Column="2" Text="{Binding Path=Count}" Margin="5,0,0,0" Foreground="{DynamicResource AccentBrush}" HorizontalAlignment="Right" />
			</Grid>
		</HierarchicalDataTemplate>

		<HierarchicalDataTemplate ItemsSource="{Binding Path=ChildObjects}" DataType="{x:Type vm:ObjectViewModel}">
			<Grid VerticalAlignment="Top" HorizontalAlignment="Left" Height="16">
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition />
				</Grid.ColumnDefinitions>

				<TextBlock Text="{Binding Path=Name}" ToolTip="{Binding Path=Name}" />
				<TextBlock Grid.Column="1" Text="{Binding Path=Class.ClassName}" ToolTip="{Binding Path=Class.FullName}" Margin="5,0,0,0" Foreground="{DynamicResource StrongBrush}" />

				<TextBlock Grid.Column="2" Text="{Binding Path=Count}" Margin="5,0,0,0" Foreground="{DynamicResource AccentBrush}" HorizontalAlignment="Right" />
			</Grid>
		</HierarchicalDataTemplate>

		<HierarchicalDataTemplate ItemsSource="{Binding Path=Objects}" DataType="{x:Type vm:ObjectsGroupViewModel}">
			<Grid VerticalAlignment="Top" HorizontalAlignment="Left" Height="16">
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition />
				</Grid.ColumnDefinitions>

				<TextBlock Text="{Binding Path=BaseClass.ClassName}" ToolTip="{Binding Path=BaseClass.ClassName}" />
				<TextBlock Grid.Column="1" Text="{Binding Path=BaseClass.Assembly}" ToolTip="{Binding Path=BaseClass.Assembly}" Margin="5,0,0,0" Foreground="{DynamicResource StrongBrush}" />

				<TextBlock Grid.Column="2" Text="{Binding Path=Count}" Margin="5,0,0,0" Foreground="{DynamicResource AccentBrush}" HorizontalAlignment="Right" />
			</Grid>
		</HierarchicalDataTemplate>
	</Window.Resources>
	<Grid Margin="10">
		<Grid.RowDefinitions>
			<RowDefinition Height="Auto" />
			<RowDefinition Height="5" />
			<RowDefinition />
		</Grid.RowDefinitions>

		<Grid Grid.ColumnSpan="3">
			<Grid.ColumnDefinitions>
				<ColumnDefinition />
				<ColumnDefinition Width="5" />
				<ColumnDefinition Width="Auto" />
			</Grid.ColumnDefinitions>

			<TextBox Text="{Binding Path=ConnectionString, UpdateSourceTrigger=PropertyChanged}" />
			<Button Grid.Column="2" Content="Connect" Command="{Binding Path=ConnectCommand}" />
		</Grid>

		<TabControl Grid.Row="2" Padding="0" Visibility="{Binding Path=RootClass, Converter={StaticResource NullToCollapsedConverter}}">
			<TabItem Header="Classes">
				<Grid>
					<Grid.ColumnDefinitions>
						<ColumnDefinition Width="300" />
						<ColumnDefinition Width="5" />
						<ColumnDefinition />
					</Grid.ColumnDefinitions>

					<TreeView BorderThickness="0,0,1,0"
							  ItemsSource="{Binding Path=RootClasses}"
							  ScrollViewer.CanContentScroll="True"
							  ScrollViewer.HorizontalScrollBarVisibility="Auto"
							  ScrollViewer.VerticalScrollBarVisibility="Auto"
							  VirtualizingStackPanel.IsVirtualizing="True"
							  VirtualizingStackPanel.VirtualizationMode="Recycling" />

					<GridSplitter Grid.Column="1" Width="5" HorizontalAlignment="Center" VerticalAlignment="Stretch" ShowsPreview="True" ResizeDirection="Columns" />

					<Grid Grid.Column="2" Visibility="{Binding Path=SelectedClass, Converter={StaticResource NullToCollapsedConverter}}">
						<ListView ItemsSource="{Binding Path=SelectedClass.Objects}">
							<ListView.View>
								<GridView>
									<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path=Name}" Width="300" />
									<GridViewColumn Header="Parent name" DisplayMemberBinding="{Binding Path=Parent.Name, FallbackValue=''}" Width="300" />
									<GridViewColumn Header="Parent class" DisplayMemberBinding="{Binding Path=Parent.Class.Name}" Width="300" />
								</GridView>
							</ListView.View>
						</ListView>
					</Grid>

					<TextBlock Grid.Column="2" Text="Select class to view." HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,100,0,0"
							   Visibility="{Binding Path=SelectedClass, Converter={StaticResource NullToCollapsedConverterInvert}}"/>
				</Grid>
			</TabItem>
			<TabItem Header="Objects">
				<Grid>
					<Grid.ColumnDefinitions>
						<ColumnDefinition Width="350" />
						<ColumnDefinition Width="5" />
						<ColumnDefinition />
						<ColumnDefinition Width="5" />
						<ColumnDefinition />
					</Grid.ColumnDefinitions>
					<Grid.RowDefinitions>
						<RowDefinition />
						<RowDefinition Height="5" />
						<RowDefinition Height="Auto" />
					</Grid.RowDefinitions>

					<TreeView Grid.RowSpan="3" BorderThickness="0,0,1,0"
							  ItemsSource="{Binding Path=RootObjects}"
							  ScrollViewer.CanContentScroll="True"
							  ScrollViewer.HorizontalScrollBarVisibility="Auto"
							  ScrollViewer.VerticalScrollBarVisibility="Auto"
							  VirtualizingStackPanel.IsVirtualizing="True"
							  VirtualizingStackPanel.VirtualizationMode="Recycling" />

					<GridSplitter Grid.RowSpan="3" Grid.Column="1" Width="5" HorizontalAlignment="Center" VerticalAlignment="Stretch" ShowsPreview="True" ResizeDirection="Columns" />

					<Grid Grid.Column="2" Visibility="{Binding Path=SelectedObject, Converter={StaticResource NullToCollapsedConverter}}">
						<TreeView ItemsSource="{Binding Path=SelectedObject.ObjectGroups}" BorderThickness="1,0,1,1" />
					</Grid>

					<Grid Grid.Row="3" Grid.Column="2" Visibility="{Binding Path=SelectedObject, Converter={StaticResource NullToCollapsedConverter}}">
						<ListView ItemsSource="{Binding Path=SelectedObject.Class.Bases}" Style="{DynamicResource ListViewNoBordersMetro}" BorderThickness="1,1,1,0" MinHeight="100">
							<ListView.ItemTemplate>
								<DataTemplate>
									<Grid VerticalAlignment="Top" HorizontalAlignment="Left" Height="16">
										<Grid.ColumnDefinitions>
											<ColumnDefinition Width="Auto" />
											<ColumnDefinition Width="Auto" />
											<ColumnDefinition />
										</Grid.ColumnDefinitions>

										<TextBlock Text="{Binding Path=ClassName}" ToolTip="{Binding Path=ClassName}" />
										<TextBlock Grid.Column="1" Text="{Binding Path=Assembly}" ToolTip="{Binding Path=Assembly}" Margin="5,0,0,0" Foreground="{DynamicResource StrongBrush}" />

										<TextBlock Grid.Column="2" Text="{Binding Path=Count}" Margin="5,0,0,0" Foreground="{DynamicResource AccentBrush}" HorizontalAlignment="Right" />
									</Grid>
								</DataTemplate>
							</ListView.ItemTemplate>
						</ListView>
					</Grid>

					<GridSplitter Grid.RowSpan="3" Grid.Column="3" Width="5" HorizontalAlignment="Center" VerticalAlignment="Stretch" ShowsPreview="True" ResizeDirection="Columns" />

					<TextBox Grid.RowSpan="3" Grid.Column="5" BorderThickness="1,0,0,0" IsReadOnly="True" Text="{Binding Path=SelectedObject.XML, Mode=OneWay}" TextWrapping="NoWrap" AcceptsReturn="True" VerticalAlignment="Stretch"
							 VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto"/>
				</Grid>
			</TabItem>
		</TabControl>
	</Grid>
</Window>
